package com.erp.warehouse.clouderp_warehouse.controller;

import com.erp.warehouse.clouderp_warehouse.pojo.inbound.InboundOrderItem;
import com.erp.warehouse.clouderp_warehouse.service.inbound.InboundOrderItemService;
import org.comple.erp.pojo.ResultStatus;
import org.comple.erp.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 2025/10/31 19:36
 * author: 向远洋
 */
@RestController
@RequestMapping("/inbound/detail")
public class InboundOrderItemController {
    @Autowired
    InboundOrderItemService service;
    /**
     * 根据入库单编码查询其所有的入库单明细
     * @param inboundCode 入库单编码(唯一，inbound的code字段设置了唯一索引)
     * @return
     */
    @PostMapping("/all")
    public AjaxResult getDetails(String inboundCode) {
        return AjaxResult.back(ResultStatus.SUCCESS, "获取入库单明细成功！")
                .add("list", service.getInboundOrderItemList(inboundCode));
    }

    /**
     * 批量添加入库明细，必填参数：
     * @param inboundOrderItemList
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addDetails(@RequestBody List<InboundOrderItem> inboundOrderItemList) {
        if(service.addInboundOrderItemList(inboundOrderItemList)) {
            return AjaxResult.back(ResultStatus.SUCCESS, "获取入库单明细成功！");
        }
        return AjaxResult.back(ResultStatus.ERROR, "获取入库单明细失败！");
    }

    @PostMapping("/delete")
    public AjaxResult deleteDetails(@RequestBody List<String> ids) {
        if(service.deleteInboundOrderItemList(ids)) {
            return AjaxResult.back(ResultStatus.SUCCESS, "删除入库单明细成功！");
        }
        return AjaxResult.back(ResultStatus.ERROR, "删除入库单明细失败！");
    }

    @PostMapping("/modify")
    public AjaxResult modifyDetail(@RequestBody InboundOrderItem inboundOrderItem){
        if(service.modifyInboundOrderItem(inboundOrderItem)) {
            return AjaxResult.back(ResultStatus.SUCCESS, "修改入库单明细成功！");
        }
        return AjaxResult.back(ResultStatus.ERROR, "修改入库单明细失败！");
    }
}
